package com.czl.module_storehouse.mvp.model;

import android.text.TextUtils;

import com.czl.base.data.bean.tengyun.LocatListBean;
import com.czl.base.data.bean.tengyun.SortBean;
import com.czl.base.data.bean.tengyun.StorehouseBean;
import com.czl.base.data.net.RetrofitClient;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_storehouse.api.ApiService;

import org.json.JSONObject;

import io.reactivex.Observable;

/**
 * @author by xubin
 * PS: Not easy to write code, please indicate.
 */
public class StockModel extends BasicDataModel {
    public Observable<HttpResponse<ListBean<LocatListBean>>> getStorehouseLocatStockInfo(String roomId) {
        JSONObject object = new JSONObject();
        try {
            object.put("storehouseId", getStorehouseId());
            if (!TextUtils.isEmpty(roomId)) {
                object.put("roomId", roomId);
            } else {
                object.put("storehouseLocatId", getStorehouseLocatId());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RetrofitClient.getInstance()
                .create(ApiService.class)
                .getStorehouseLocatStockInfo(createBody(object));
    }

    public Observable<HttpResponse<SortBean>> getStorehouseSortStockInfo(Integer sortId, String sortCode) {
        JSONObject object = new JSONObject();
        try {
            object.put("sortId", sortId);
            object.put("storehouseId", getStorehouseId());
            object.put("sortCode", sortCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RetrofitClient.getInstance()
                .create(ApiService.class)
                .getStorehouseSortStockInfo(createBody(object));
    }

    public Observable<HttpResponse<ListBean<SortBean>>> getStorehouseStockInfo(int pageNo, String name) {
        JSONObject object = new JSONObject();
        try {
            object.put("companyId", getManageCompanyId());
            object.put("sortName", name);
            object.put("storehouseId", getStorehouseId());
            object.put("pageNo", pageNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RetrofitClient.getInstance()
                .create(ApiService.class)
                .getStorehouseStockInfo(createBody(object));
    }

    public Observable<HttpResponse<ListBean<StorehouseBean.StockWarnBean>>> getStorehouseStockWarnList(String storehouseId) {
        JSONObject object = new JSONObject();
        try {
            object.put("storehouseId", storehouseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RetrofitClient.getInstance()
                .create(ApiService.class)
                .getStorehouseStockWarnList(createBody(object));
    }
}
